package sagroup.testing;

import java.util.HashMap;
import java.util.LinkedList;

import lights.adapters.Field;
import lights.adapters.Tuple;
import lights.interfaces.ITuple;
import lime2.Location;
import sagroup.dracots.DracoTS;
import sagroup.dracots.DracoTuple;
import sagroup.dracots.FlatShareTuple;
import sagroup.dracots.TupleType;

public class TestDeregisterWeakReaction implements Runnable {
	DracoTS dts = null;
	private FlatShareTuple makeNewTuple(String typeName, int num) {
		ITuple it = new Tuple();
		it.add(new Field().setValue(num));
		return new FlatShareTuple(new TupleType(typeName), it);
	}
	public void run() {
		try {
			dts = DracoTS.get("Test");
			HashMap<String, LinkedList<FlatShareTuple>> tuples = new HashMap<String, LinkedList<FlatShareTuple>>();
			for (int i = 'A'; i <= 'B'; i++) {
				String type = String.valueOf((char) i);
				LinkedList<FlatShareTuple> list = new LinkedList<FlatShareTuple>();
				tuples.put(type, list);
				for (int j = 1; j <= 3; j++) {
					list.add(makeNewTuple(type, j));
				}
			}
			for (LinkedList<FlatShareTuple> list : tuples.values()) {
				for (FlatShareTuple t : list) {
					dts.out(t);
					System.out.println("Agent out tuple " + t.getType() + "-"
							+ t.getVID());
				}
			}
			FlatShareTuple template = (FlatShareTuple) FlatShareTuple
					.createMatchAllTemplateByClass(FlatShareTuple.class);
			template.setType(new TupleType("A"));
			template.setCurr(Location.UNSPECIFIED);
			template.setDest(Location.UNSPECIFIED);
			DracoTuple ret = dts.rd(template);
		} catch (Exception ex) {
			System.out.print(ex.getMessage());
		}
	}
}
